package com.gitee.wsl.common.draw.gesture.computator

import com.gitee.wsl.common.draw.area.Viewport

/**
 * Version of ChartComputator for preview charts. It always uses maxViewport as visible viewport and currentViewport as
 * preview area.
 */
class PreviewChartCommutator : ChartCommutator() {

    override var visibleViewport: Viewport
        get() = maximumViewport
        set(value) {
            setMaxViewport(value)
        }

    override fun computeRawX(valueX: Float): Float {
        val pixelOffset: Float = (valueX - maximumViewport.left) * (contentRectMinusAllMargins.width() / maximumViewport.width)
        return contentRectMinusAllMargins.left + pixelOffset
    }

    override fun computeRawY(valueY: Float): Float {
        val pixelOffset: Float = (valueY - maximumViewport.bottom) * (contentRectMinusAllMargins.height() / maximumViewport.height)
        return contentRectMinusAllMargins.bottom - pixelOffset
    }
}